<div class="layui-row" style="margin-top:20px;">
	<div class="layui-col-xs6 layui-col-sm6 layui-col-md4" style="text-align:center">
		<button type="button" class="layui-btn layui-btn-normal scan">扫菲码</button>
    </div>
    <div class="layui-col-xs6 layui-col-sm6 layui-col-md4" style="text-align:center">
		<a href="{:url('system/publics/logout')}" class="layui-btn layui-btn-danger">注销</a>
    </div>
</div>

<div class="layui-row" id="info" style="margin-top:20px;"></div>

<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
<script type="text/javascript" src='https://cdn.bootcdn.net/ajax/libs/vConsole/3.3.4/vconsole.min.js'></script>

<script type="text/javascript"> 
	wx.config({:json_encode($wxConfig)});
	wx.ready(function(){
		layui.layer.msg('wx ready success', {time: 3000});
	});
	wx.error(function(res){
		console.log(res);
		layui.layer.msg('wx ready error', {time: 3000});
	});
	
	window.vConsole = new window.VConsole();
	console.log("Hello vConsole");
	
    layui.use(['tool', 'layer'], function() {
    	var $ = layui.jquery;
    	var layer = layui.layer;
    	
    	layer.msg("您好，{:session('admin_user')['nick']}", {icon: 1});
    	
    	// 扫菲码
		$(document).on('click','.scan',function(){
			$('#info').html('');
			wx.scanQRCode({
				  needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
				  scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
				  success: function (res) {
				  		var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
				  		$.ajax({
					 		   type: "POST",
					 		   url: "{:url('getQrcodeInfo')}",
					 		   data: "qrcode="+result,
					 		   dataType:"json",
					 		   success: function(res){
					 			  if (res.code == 1) {
					 				 $('#info').html(res.msg+'<button type="button" class="layui-btn over" data-id="'+res.data.mid+'">完成菲码</button>');
								  } else {
									 layer.msg(res.msg, {icon: 2,anim: 6});
								  }
					 		   }
					 	});
				  }
			})
		});
    	
		// 完成菲码
		$(document).on('click','.over',function(){
			var mid = $(this).attr('data-id');
			$.ajax({
		 		   type: "POST",
		 		   url: "{:url('over')}",
		 		   data: "mid="+mid,
		 		   dataType:"json",
		 		   success: function(res){
		 			  if (res.code == 1) {
		 				 $('#info').html('');
						 layer.msg(res.msg, {time:2000, icon: 1,end:function(){$(".scan").trigger("click")}});
					  } else {
						 layer.msg(res.msg, {icon: 2,anim: 6});
					  }
		 		   }
		 	})
		});
    });
</script>